<?php

namespace App\Providers;

use App\Models\Domain\Induce\ExcelQueue;
use Illuminate\Pagination\Paginator;

use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Log;
use Queue;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // 限制数据长度
        Schema::defaultStringLength(191);
        //引用bootstrap样式
	    Paginator::useBootstrap();

        Queue::failing(function (JobFailed $event) {
            // $event->connectionName
            // $event->job
            // $event->exception
          //  var_dump('queue -----------',$event->exception);
           // var_dump('queue -----------',$event->job);
            if ($event->job->resolveName() =='App\Jobs\ExcelImport'){
                Log::channel('excel')->error($event->exception->getMessage(), [
                    'resolveName'=>$event->job->resolveName(),
                    'queue'=>$event->job->getQueue(),
                ]);
                 ExcelQueue::where('queue_name', '域名归纳')
                    ->where('type', 1)->
                    update(['status'=> true,'remarks'=> '导入失败:'.$event->exception->getMessage()]);
            }

         //   var_dump($event->job->resolveName());   //"App\Jobs\ExcelImport"
         //      var_dump($event->job->getQueue());   //"default"
         //   var_dump($event->job->hasFailed());  // bool(true)   是否失败
         //   var_dump($event->exception->getMessage());   //错误信息
         //   var_dump($event->job->timeout());  // bool(true)   是否超时


        });
        Queue::after(function (JobProcessed $event){
            dump($event->job->resolveName());
            dump($event->job->getQueue());
//            if ($event->job->getQueue() !='manager_export'){
//                dump($event->job->getQueue());
//            }

        });
         dump('大小'. Queue::size()); //队列数量
        //   dump( '队列名称'. Queue::getName()); //队列名称
        //  dump('连接名称'. Queue::getConnectionName()); //连接名称
        //   dump('驱动名称'. Queue::getDefaultDriver()); //驱动名称
        Queue::before(function (JobProcessing $event){
        //   dump($event->job->resolveName()) ;
        });





    }
}
